<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="请求id" prop="requestId">
        <el-input
          v-model="queryParams.requestId"
          placeholder="请输入请求id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="请求方式" prop="requestMethod">
        <el-input
          v-model="queryParams.requestMethod"
          placeholder="请输入请求方式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="请求路径" prop="requestPath">
        <el-input
          v-model="queryParams.requestPath"
          placeholder="请输入请求路径"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="模块名" prop="moduleName">
        <el-input
          v-model="queryParams.moduleName"
          placeholder="请输入模块名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="响应状态" prop="responseStatus">
        <el-input
          v-model="queryParams.responseStatus"
          placeholder="请输入响应状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户id" prop="optionUserId">
        <el-input
          v-model="queryParams.optionUserId"
          placeholder="请输入请求用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户名称" prop="optionUserName">
        <el-input
          v-model="queryParams.optionUserName"
          placeholder="请输入请求用户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:systemlog:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="clean"
          v-hasPermi="['system:systemlog:clean']"
        >清空</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="systemlogList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="请求id" align="center" prop="requestId" />
      <el-table-column label="请求方式" align="center" prop="requestMethod" />
      <el-table-column label="请求路径" align="center" prop="requestPath" show-overflow-tooltip/>
      <el-table-column label="IP地址" align="center" prop="requestIp" />
      <el-table-column label="请求地址" align="center" prop="requestUri" show-overflow-tooltip/>
      <el-table-column label="设备标识" align="center" prop="requestSign" show-overflow-tooltip/>
      <el-table-column label="请求参数" align="center" prop="requestParams" show-overflow-tooltip/>
      <el-table-column label="模块名" align="center" prop="moduleName" />
<!--      <el-table-column label="类名" align="center" prop="className" />
      <el-table-column label="方法" align="center" prop="methodName" />
      <el-table-column label="方法入参" align="center" prop="methodParams" show-overflow-tooltip/> -->
      <el-table-column label="方法返回值" align="center" prop="methodReturn" show-overflow-tooltip/>
      <el-table-column label="响应状态" align="center" prop="responseStatus" />
      <el-table-column label="开始时间" align="center" prop="beginTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beginTime, '{y}-{m}-{d} {h}:{s}:{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="执行总时间" align="center" prop="execTime" />
      <el-table-column label="异常信息" align="center" prop="exceptionInfo" show-overflow-tooltip/>
      <el-table-column label="请求用户id" align="center" prop="optionUserId" />
      <el-table-column label="请求用户名称" align="center" prop="optionUserName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:systemlog:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
    import {
        addSystemlog,
        delSystemlog,
        getSystemlog,
        listSystemlog,
        updateSystemlog,
        cleanSystemLog
    } from "@/api/system/systemlog";

export default {
  name: "Systemlog",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 系统日志表格数据
      systemlogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        requestId: null,
        requestMethod: null,
        requestPath: null,
        requestIp: null,
        requestUri: null,
        requestSign: null,
        requestParams: null,
        moduleName: null,
        className: null,
        methodName: null,
        methodParams: null,
        methodReturn: null,
        responseStatus: null,
        beginTime: null,
        execTime: null,
        optionUserId: null,
        optionUserName: null,
        exceptionInfo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询系统日志列表 */
    getList() {
      this.loading = true;
      listSystemlog(this.queryParams).then(response => {
        this.systemlogList = response.data;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        requestId: null,
        requestMethod: null,
        requestPath: null,
        requestIp: null,
        requestUri: null,
        requestSign: null,
        requestParams: null,
        moduleName: null,
        className: null,
        methodName: null,
        methodParams: null,
        methodReturn: null,
        responseStatus: null,
        beginTime: null,
        execTime: null,
        optionUserId: null,
        optionUserName: null,
        exceptionInfo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.requestId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const requestIds = row.requestId || this.ids;
      this.$confirm('是否确认删除系统日志编号为"' + requestIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSystemlog(requestIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 清空 */
    clean(){
      this.$confirm('是否确认清空所有系统日志?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return cleanSystemLog();
        }).then(() => {
          this.getList();
          this.msgSuccess("清空成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/systemlog/export', {
        ...this.queryParams
      }, `system_systemlog.xlsx`)
    }
  }
};
</script>
